home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
014
/
markatrb.arc
/
MARK.ASM
next >
Wrap
Assembly Source File
|
1985-11-16
|
7KB
|
263 lines
name mark
page 55,132
title 'MARK --- set attribute of file'
;
; MARK --- Utility to set attribute of file.
;
; Requires PC-DOS 2.0 or higher for execution.
;
; Program is called by command of the form:
;
; A>MARK path\file.ext /x
;
; where x=A for Archive, H for hidden, R for read-only,
; or N for normal (all attrib bits off).
;
;
; Copyright (c) 1985 Charles C. Caro
;
; May be freely modified and reproduced
; for non-commercial use.
;
cr equ 0dh ;ASCII carriage return
lf equ 0ah ;ASCII line feed
eom equ '$' ;end of message flag
command equ 80h ;Command line buffer
rd_only equ 01h ;file attributes
hidden equ 02h
system equ 04h
volume equ 08h
subdir equ 10h
archive equ 20h
cseg segment para public 'CODE'
assume cs:cseg,ds:data,es:data,ss:stack
mark proc far ;entry point from PC-DOS
push ds ;save DS:0000 for final
xor ax,ax ;return to PC-DOS
push ax
mov ax,data ;make our data segment addressable
mov es,ax ;via the ES register
call infile ;get path and name for
;file to be modified.
jnc mark1 ;jump if filename was ok
mov dx,offset msg1 ;filename absent or illegal,
call error ;print error message and exit
ret
mark1: ;filename was ok, now try
call get_switch ;and find the switch
jnc mark2 ;jump if switch was ok
mov dx,offset msg7 ;missing switch, print error
call error ;message and exit
ret
mark2: ;found legal switch, now
push dx ;save addr of success message
mov ax,es ;make our data segment addressable
mov ds,ax ;via the DS register
;CX=attrib bits,
; already set by "get_switch"
;DS:DX=addr of filename
mov dx,offset input_name
mov ah,43h ;function 43h=CHMOD
mov al,01 ;AL=01 for set attrib
int 21h ;make request to PC-DOS
jnc mark3 ;if CY=0 jump, successful call
;if CY=1 call failed,
pop dx ;clean up stack, and
mov dx,offset msg2 ;print error message
call error
ret
mark3: ;attribute was modified,
mov dx,offset msg3 ;print 1st part of success message
mov ah,9
int 21h
;print filename
mov dx,offset input_name
call pasciiz
pop dx ;print last part of success msg.
mov ah,9
int 21h
ret ;final exit to PC-DOS
mark endp
pasciiz proc near ;print the ASCIIZ string
;whose offset is in DX on
;the standard output device.
;Regs AX, BX also destroyed.
mov bx,dx ;let BX=offset of string
pasciiz1:
mov dl,[bx] ;get next char from string
or dl,dl ;if char.=zero,end of string
jz pasciiz9 ;jump if end
cmp dl,'A' ;if it is an upper-case alpha
jb pasciiz2 ;character,fold to lower case
cmp dl,'Z' ;Note: Inclusive Or of an alpha
ja pasciiz2 ;ASCII character with 20h has the
or dl,20h ;effect of folding to lower case.
pasciiz2:
mov ah,2 ;function 2=output char.
int 21h ;request output by PC-DOS
inc bx ;advance to next string position
jmp short pasciiz1
pasciiz9: ;done with string output,
ret ;return to caller
pasciiz endp
infile proc near ;Capture the name of a file
;from the command tail buffer
;where it was left by PC-DOS,
;transferring it into a local
;buffer in the form of an
;ASCIIZ string.
;DS:SI <- addr of command tail
mov si,offset command
;ES:DI <- addr of local buffer
mov di,offset input_name
cld ;make sure direction flag cleared
lodsb ;first check count byte to make
or al,al ;sure command tail is present
jz infile4 ;return error status if not.
infile1: ;scan over leading blanks to
lodsb ;find the path and filename
cmp al,cr ;if we run into carriage return,
jz infile4 ;filename is missing so exit.
cmp al,20h ;if this char is a blank,
jz infile1 ;keep scanning.
infile2: ;found 1st char of name,
stosb ;transfer the name to local buffer.
lodsb ;check next character, found
cmp al,cr ;end of string yet?
je infile3 ;yes if either carriage return
cmp al,20h
jne infile2
infile3: ;path and filename successfully
xor al,al ;transferred to local buffer,
stosb ;store 0 byte at end of string
clc ;and exit with Carry flag =0
ret
infile4: ;some type of error was detected
stc ;so exit with Carry flag =1
ret
infile endp
get_switch proc near ;Scan the input line for a "/"
;delimiting a switch, then make
;sure it is legal.
;Return CY=0 if legal switch, and
;CX=attrib byte, DX=msg addr
;Return CY=1 if switch no good
mov si,offset command+1 ; DS:SI = addr of command line
get_switch1: ;look for "/" character
lodsb
cmp al,cr ;if we run into a carriage return,
jz get_switch9 ;switch missing so take error exit.
cmp al,'/'
jne get_switch1 ;not '/' yet, keep looking.
lodsb ;found '/', pick up next char.
or al,20h ;and fold to lower case.
cmp al,'r' ;R = read only
jne get_switch2 ;not R, jump
mov cx,rd_only ;R so set read only attrib bit
mov dx,offset msg5
ret ;return CY=0 for success
get_switch2: ;check for H=hidden
cmp al,'h'
jne get_switch3 ;not H, jump
mov cx,hidden ;H so set hidden attrib bit
mov dx,offset msg4
ret ;return CY=0 for success
get_switch3: ;check for N=normal
cmp al,'n'
jne get_switch4 ;not N,jump
mov cx,0 ;clear all attrib bits
mov dx,offset msg6
ret ;return CY=0 for success
get_switch4: ;check for A=Archive
cmp al,'a'
jne get_switch9 ;not A,jump to error exit
mov cx,archive ;A so set archive attrib bit
mov dx,offset msg8
ret ;return CY=0 for success
get_switch9: ;missing or illegal switch,
stc ;return CY flag=1 as alarm
ret
get_switch endp
error proc near ;print error message
mov ax,data ;make sure data area addressable
mov ds,ax
mov ah,9 ;print error type
int 21h
mov dx,offset helpmsg
mov ah,9 ;also print HELP information
int 21h
ret ;back to caller
error endp
cseg ends
;declare a data segment for
;storage of miscellaneous
;constants and variables
data segment para public 'DATA'
input_name db 64 dup (0) ;buffer for path and file name
msg1 db cr,lf
db 'Missing file name.',eom
msg2 db cr,lf
db 'File not found.',eom
msg3 db cr,lf
db 'Attribute of file ',eom
msg4 db ' has been set to Hidden.'
db cr,lf,eom
msg5 db ' has been set to Read-Only.'
db cr,lf,eom
msg6 db ' has been set to Normal.'
db cr,lf,eom
msg7 db cr,lf
db 'Missing or illegal switch.',eom
msg8 db ' has been set to Archive.'
db cr,lf,eom
helpmsg db ' Command should be in the form: '
db cr,lf,lf
db ' MARK filename /x'
db cr,lf,lf
db 'x=A for archive, H for hidden, N for normal, R for read-only.'
db cr,lf,eom
data ends
;declare a stack segment of 64 bytes
;for use as scratch area by such
;instructions as PUSH, POP, CALL, RET
stack segment para stack 'STACK'
db 64 dup (?)
stack ends
end mark